/*
 * 
 *  This file is part of Sourceprojects.org Lycia Copyright 2010 noctarius
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 * 
 */
package org.sourceprojects.lycia.internal.logging;

import android.util.Log;

public class AndroidCompatibleLogger extends LyciaLoggerWrapper {

	AndroidCompatibleLogger(final String tag) {
		super(tag);
	}

	@Override
	public void debug(final Object message) {
		Log.d(getTag(), wrapObject(message));
	}

	@Override
	public void debug(final Object message, final Throwable t) {
		Log.d(getTag(), wrapObject(message), t);
	}

	@Override
	public void error(final Object message) {
		Log.e(getTag(), wrapObject(message));
	}

	@Override
	public void error(final Object message, final Throwable t) {
		Log.e(getTag(), wrapObject(message), t);
	}

	@Override
	public void fatal(final Object message) {
		Log.e(getTag(), wrapObject(message));
	}

	@Override
	public void fatal(final Object message, final Throwable t) {
		Log.e(getTag(), wrapObject(message), t);
	}

	@Override
	public void info(final Object message) {
		Log.i(getTag(), wrapObject(message));
	}

	@Override
	public void info(final Object message, final Throwable t) {
		Log.i(getTag(), wrapObject(message));
	}

	@Override
	public void warn(final Object message) {
		Log.w(getTag(), wrapObject(message));
	}

	@Override
	public void warn(final Object message, final Throwable t) {
		Log.w(getTag(), wrapObject(message));
	}

	@Override
	public boolean isDebugEnabled() {
		return Log.isLoggable(getTag(), Log.DEBUG);
	}

	@Override
	protected String getTag() {
		final String tag = super.getTag();
		if (tag.length() > 23) {
			return tag.substring(tag.length() - 23);
		}

		return tag;
	}

	private String wrapObject(final Object message) {
		return message.toString();
	}
}
